package com.test.jxls;

import org.jxls.reader.ReaderBuilder;
import org.jxls.reader.XLSReader;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JxlsReadDemo {

    public static void main(String[] args) {
        String path = "D:\\附件六：业务权限配置表-方杰电子商务-2020-11-23.xlsx";
        //path 要读的Excel的路径
        String xmlConfig = "D:\\xmlConfig.xml"; //xml文件名
        try {
            //构建xml文件输入流
            InputStream inputXML = new BufferedInputStream(new FileInputStream(xmlConfig));
            //绑定xml文件
            XLSReader mainReader = ReaderBuilder.buildFromXML(inputXML);
            //构建文件输入流
            InputStream inputXLS = new FileInputStream(path);
            //通过低级流构建，高级流
            BufferedInputStream bis = new BufferedInputStream(inputXLS);
            DataSixUpload data = new DataSixUpload();
            List<DataSixUpload> dataList = new ArrayList<>();
            Map<String, Object> beans = new HashMap<>();
            beans.put("data", data);
            beans.put("dataList", dataList);
            //通过XSLReader 的read方法，它会自动映射pojo类，得到数据集合
            mainReader.read(bis, beans);
            for (DataSixUpload d : dataList) {
                System.out.println(String.format("%s, %s", d.getUserCode(), d.getResult()));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }
}
